#include <bits/stdc++.h>
using namespace std ;
const int MAXN = 2e5 + 10 ;
int t , n , ans ;
vector <int > r , b ;
int a [MAXN] , dp[MAXN] ;
void re_set ()
{
    r.clear () , b.clear () ;
    ans = 0 ;
}
int t1 ()
{
    int c = 0 ;
    int rlen = r.size () , blen = b.size () ;
    for (int i = 1;i < rlen ;++ i)
    {
        if (a[r[i]] == a[r[i - 1]] ) c += a[r[i]] ;
    }
    for (int i = 1;i < blen ;++ i)
    {
        if (a [b[i]] == a [b[i - 1]]) c += a[b[i]] ;
    }
    return c ;
}
void rec (int i)
{
    if (i == 0)
    {
        ans = max (ans , t1 () ) ;
        return ;
    }
    r.push_back (i) ;
    rec (i - 1) ;
    r.erase (r.end () - 1 , r.end () ) ;
    b .push_back (i) ;
    rec (i - 1) ;
    b.erase (b.end () - 1 , b.end() ) ;
}
int main ()
{
    freopen ("color.in" , "r" , stdin) ;
    freopen ("color.out" , "w" , stdout) ;
    cin >> t ;
    for (int i = 1;i <= t;++ i)
    {
        re_set () ;
        cin >> n ;
        for (int i = 1;i <= n;++ i)
        {
            cin >> a[i] ;
        }
        rec (n) ;
        cout << ans << endl ;
    }
    return 0 ;
}
